package org.openmore.consumer.service.feign;

import io.swagger.annotations.ApiParam;
import org.openmore.consumer.dto.common.BaseResponse;
import org.openmore.consumer.dto.common.ResourcesDto;
import org.openmore.consumer.dto.common.StringParams;
import org.openmore.consumer.entity.enums.ResourceType;
import org.openmore.consumer.service.feignImpl.ResourceServiceImpl;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import static org.springframework.http.MediaType.APPLICATION_JSON_UTF8_VALUE;

@Service
@FeignClient(value = "openmore-storage", fallbackFactory = ResourceServiceImpl.class)
public interface ResourceService {


    @RequestMapping(method = RequestMethod.GET, value = "/api/resources/query")
    public BaseResponse selectAllByPage(@RequestParam(required = false) @ApiParam(value = "资源名称") String name,
                                        @RequestParam(required = false) @ApiParam(value = "资源存储key") String key,
                                        @ApiParam(value = "资源类型:IMAGE:图片、AUDIO：音频、VIDEO：视频、OTHERS:其它类型") ResourceType type,
                                        @RequestParam(required = false) @ApiParam(value = "开始时间") Date startTime,
                                        @RequestParam(required = false) @ApiParam(value = "结束时间") Date endTime,
                                        @RequestParam(required = false, defaultValue = "1") @ApiParam(value = "分页第几页") Integer pageNum,
                                        @RequestParam(required = false, defaultValue = "10") @ApiParam(value = "每页多少记录") Integer pageSize);



    @RequestMapping(method = RequestMethod.GET, value = "/api/resources/{id}")
    public BaseResponse getResourcesById(@PathVariable @ApiParam(required = true, value = "id") String id);

    @RequestMapping(method = RequestMethod.PUT)
    public BaseResponse updateResources(@RequestBody @ApiParam(value = "新信息", required = true) ResourcesDto resources);

    @RequestMapping(method = RequestMethod.POST)
    public BaseResponse addVideoResources(@RequestBody @ApiParam(value = "新资源", required = true) ResourcesDto resources);
    /**批量创建*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/resources/files")
    public BaseResponse insertResources(@RequestParam(value = "files") MultipartFile[] files);

    /**单文件上传*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/resources/file")
    public BaseResponse insertResource(@RequestParam(value = "file") MultipartFile file);

    /**获得直传Token*/
    @RequestMapping(method = RequestMethod.GET, value = "/api/resources/uploadToken")
    public BaseResponse getUploadToken();

    /**物理删除阿里云图片*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/resources/oss/physical")
    public BaseResponse deleteOssResource(@RequestBody @ApiParam(value = "oss对像名") StringParams fileName);
    /**删除指定资源*/
    @RequestMapping(method = RequestMethod.DELETE, value = "/api/resources/{id}")
    public BaseResponse deleteResources(@PathVariable @ApiParam(value = "id", required = true) String id);

    /**下载指定资源*/
    @RequestMapping(method = RequestMethod.GET, value = "/api/resources/{id}/download")
    public BaseResponse downloadResources(@PathVariable @ApiParam(value = "id", required = true) String id);

    /**oss直传Token回调*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/resources/uploadCallback", produces = {"application/json;charset=UTF-8"}, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public BaseResponse uploadCallback(
            @RequestParam(required = false) @ApiParam(value = "文件名") String filename,
            @RequestParam(required = false) @ApiParam(value = "文件大小") String size,
            @RequestParam(required = false) @ApiParam(value = "文件类型") String mimeType,
            @RequestParam(required = false) @ApiParam(value = "高度") String height,
            @RequestParam(required = false) @ApiParam(value = "宽度") String width);

    /**导入保利数据*/
    @RequestMapping(method = RequestMethod.POST, value = "/api/resources/parseExcelPolvs", produces = {APPLICATION_JSON_UTF8_VALUE})
    public BaseResponse parseExcelProducts(@RequestParam() @ApiParam(value = "excel文件") MultipartFile file);

    /**下载保利数据导入模板*/
    @RequestMapping(method = RequestMethod.GET, value = "/api/resources/parsePolvExcelModel")
    public BaseResponse parseExcelModel();

    /**测试鉴权*/
    @RequestMapping(method = RequestMethod.GET, value = "/api/resources/testAuth")
    public BaseResponse test(@RequestParam(required = false) @ApiParam String str);
}
